package com.hhkj.admin.invoice.controller;

import com.hhkj.admin.invoice.common.cont.InvoiceConst;
import com.hhkj.admin.invoice.domain.Invoice;
import com.hhkj.admin.invoice.model.req.InvoiceReq;
import com.hhkj.admin.invoice.model.res.InvoiceRes;
import com.hhkj.admin.invoice.service.biz.InvoiceBizService;
import com.hhkj.admin.sale.common.cont.SaleCommissionConst;
import com.hhkj.admin.sale.model.req.SaleCommissionReq;
import com.ruoyi.common.annotation.PermissionPrefix;
import com.ruoyi.common.base.biz.controller.v2.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.excl.utils.ExcelUtils;
import com.ruoyi.common.valid.VAdd;
import com.ruoyi.common.valid.VEdit;
import com.ruoyi.common.valid.VPage;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@RestController
@RequestMapping("/invoice")
@PermissionPrefix("course:orderInvoice")
public class InvoiceController extends BaseController<Invoice, InvoiceReq, InvoiceRes, InvoiceBizService> {

    /** 分佣数据导出 */
    @PostMapping("/export")
    public void export(@RequestBody InvoiceReq invoiceReq, HttpServletResponse response)
    {
        ExcelUtils.downLoadExcel(InvoiceConst.EXPORT_EXCEL_TITLE, response, this.getBizService().createExportWorkbook(invoiceReq));
    }

    @PutMapping("/invoicing")
    public AjaxResult invoicing(@RequestBody @Validated(value = VEdit.class) InvoiceReq invoiceReq) {
        return AjaxResult.success(this.getBizService().invoicing(invoiceReq));
    }

    @PutMapping("/discard/{id}")
    public AjaxResult discard(@PathVariable("id") Long id) {
        return AjaxResult.success(this.getBizService().discard(id));
    }

    @PutMapping("/reapply/{id}")
    public AjaxResult reapply(@PathVariable("id") Long id) {
        return AjaxResult.success(this.getBizService().reapply(id));
    }

    @Override
    @PostMapping("/paging")
    @PreAuthorize("@ss.hasPermi(this, 'page')")
    public TableDataInfo paging(@Validated(VPage.class) @RequestBody InvoiceReq invoiceReq) {
        return super.paging(invoiceReq);
    }
}
